<%-- 
    Document   : habilitados
    Created on : 14-jun-2012, 17:15:28
    Author     : Administrador
--%>
<%@page import="com.util.UtilTransaccion"%>
<%@page import="com.javabeans.Facultad"%>
<%@page import="com.javabeans.Gestion"%>
<%@page import="com.javabeans.VentaMatricula"%>
<%@include file="../../../controlSession.jsp" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<%
    List<Gestion> gestiones = (List<Gestion>)request.getAttribute("gestiones");
    List<VentaMatricula> vms = (List<VentaMatricula>)request.getAttribute("vms");
%>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>SI-ESFM </title>
        <meta name="description" content="Derechos Reservados SI-ESFM." />
        <link rel="stylesheet" href="<%=s_path%>/css/styles.css" type="text/css" />
        <link rel="stylesheet" href="<%=s_path%>/css/menu/style.css" type="text/css" />
        <link rel="stylesheet" href="<%=s_path%>/css/themes/start/jquery-ui-1.8.20.custom.css" type="text/css" />
        <link rel="stylesheet" href="<%=s_path%>/css/themes/start/jquery.ui.timepicker.css?v=0.3.0" type="text/css" />
        <link rel="shortcut icon" href="<%=s_path%>/images/ico.png" type="image/png"/>
        
        <script type="text/javascript" src="<%=s_path%>/js/jquery-1.7.2.min.js"></script>
        <script type="text/javascript" src="<%=s_path%>/js/validate/jquery.validate.min.js"></script>
        <script type="text/javascript" src="<%=s_path%>/js/ui/minified/jquery.ui.core.min.js"></script>  <!--si o si cargar esto-->
        <script type="text/javascript" src="<%=s_path%>/js/ui/minified/jquery.ui.widget.min.js"></script>
        <script type="text/javascript" src="<%=s_path%>/js/ui/minified/jquery.ui.position.min.js"></script>
        <script type="text/javascript" src="<%=s_path%>/js/ui/minified/jquery.ui.mouse.min.js"></script>
        <script type="text/javascript" src="<%=s_path%>/js/ui/minified/jquery.ui.button.min.js"></script>
        <script type="text/javascript" src="<%=s_path%>/js/ui/minified/jquery.ui.draggable.min.js"></script>
        <script type="text/javascript" src="<%=s_path%>/js/ui/minified/jquery.ui.resizable.min.js"></script>
        <script type="text/javascript" src="<%=s_path%>/js/ui/minified/jquery.ui.dialog.min.js"></script>
        <script type="text/javascript" src="<%=s_path%>/js/ui/minified/jquery.effects.core.min.js"></script>
        <script type="text/javascript" src="<%=s_path%>/js/ui/minified/jquery.ui.datepicker.min.js"></script>
        <script type="text/javascript" src="<%=s_path%>/js/ui/jquery.ui.timepicker.js?v=0.3.0"></script>
    </head>
    <script type="text/javascript">
            
        $(document).ready(function(){
            //  hora
            $('#horaIni\\.\\[1\\]').timepicker();
            $('#horaFin\\.\\[1\\]').timepicker();
            
            // rango de fecha
            $( "#fechaIni" ).datepicker({
                    defaultDate: "+1w",
                    changeMonth: true,
                    changeYear: true,
                    numberOfMonths: 2,
                    onSelect: function( selectedDate ) {
                            $( "#fechaFin" ).datepicker( "option", "minDate", selectedDate );
                    }
            });
            $( "#fechaFin" ).datepicker({
                    defaultDate: "+1w",
                    changeMonth: true,
                    numberOfMonths: 3,
                    onSelect: function( selectedDate ) {
                            $( "#fechaIni" ).datepicker( "option", "maxDate", selectedDate );
                    }
            });

            $("#dialogo").dialog({
                autoOpen: false,
                title: "Formulario Habilitaci&oacute;n de Venta de Matru00edcula",
                height: 300,
                width: 1000,
                modal: true,
                buttons: {
                    "Aceptar": function() {
                        var flag = $("#formVentaMatricula").valid();
                        if(flag){
                            $.ajax({
                                type: 'POST',
                                url: 'Operaciones',
                                data: $('#formVentaMatricula').serialize(),
                                success: function(res){
                                    $('#listVentas').html(res);
                                },
                                error:function(){alert("Error! al registrar la habilitacion de matricula")}
                            });
                            $( this ).dialog( "close" );
                        }
                    },
                    Cancelar: function() {
                        $( this ).dialog( "close" );
                    }
                },
                close: function() {
                    // implementar lo que convenga
                }
            });

           // boton add Unidad Académica
           $.fn.addVentaMatricula = function(){
                $('#formVentaMatricula').each(function(){
                    this.reset();
                });
                resetGestion();
                
                $("#titleForm").text("Habilitar Venta Matricula");
                $("#accion").val("2");
                $("#fechaIni").val("");
                $("#horaIni").val("");
                $("#fechaFin").val("");
                $("#horaFin").val("");
                $( "#dialog:ui-dialog" ).dialog( "destroy" );
                $( "#dialogo" ).dialog( "open" );
                $("#idGestion").focus();
           }
           
           // baja cliente corporativo
            $.fn.cancelarVentaMatricula = function(idVentaMatricula){
                if(confirm("¿Esta seguro de cancelar la habilitacion de venta de matricula?")){
                    $.ajax({
                        url: "Operaciones",
                        type: "GET",
                        data:{ accion:3, idVentaMatricula:idVentaMatricula},
                        success:function(res){
                            $('#listVentas').html(res);
                        },
                        error: function(res){ alert("Error! al cancelar la habilitacion de venta de matricula"); }
                    });
                }
            }

        });

        function resetGestion(){
            document.getElementById("idGestion").selectedIndex = 0;
        }

    </script>
    <body onload="showTime(<%=s_param%>)">
        <div id="top-wrap">
            <!-- cabeza principal -->
            <%@include file="../../../head.jsp" %>
            
            <!-- cuerpo -->
            <div id="bodySpace">               
                <!-- aqui va la ruta -->
                <div class="clearfix" id="middle">
                    <!-- aqui va el arbol de entrada -->
                    <div id="breadcrumb"><!-- le da la forma de la imagen -->
                        <ul>
                        <li><a>Home</a></li>
                        <li><span style="color:#666">Operaciones</span></li>
                        <li class="current-page"><span class="end"><span class="middle">Habilitar Venta Matr&iacute;cula</span></span></li>
                        </ul>
                        <!-- para la hora -->
                        <div style="clear: both;position: absolute;text-align: right;width: 100%;"><span id="fechaServ"></span>&nbsp;&nbsp;<span id="horaServ" style=""></span>&nbsp;</div>
                    </div><!-- begin SIDEBAR FIRST -->
                </div>
                
                <div id="principal">
                    <!-- todo el cuerpo disponible para el area de trabajo -->
                    <div class="cuerpoCompleto" style="border: 0px solid">
                        <div class="innerLeft" style="border: 0px solid">
                            <!-- supuestamente aca biene el contenido -->
                            <center>
                            <div id="listVentas">
                                
                                <h2 class="decorado">Venta de Matr&iacute;culas habilitadas para la gesti&oacute;n vigente y posterior</h2>
                            <table class="miReporte" style="width: 100%">
                                <tr>
                                    <td style="text-align: right"><input type="button" class="boton" value="Nueva Venta Matr&iacute;cula" onclick="$.fn.addVentaMatricula()"/></td>
                                </tr>
                            </table>
                            <table class="tabla_decorado" style="width: 100%">
                                <thead>
                                    <tr><!--  -->
                                        <th width="15%" class="th_decoradoRowspan">CIUDAD</th>
                                        <th width="20%" class="th_decoradoRowspan">UNIDAD ACADEMICA</th>
                                        <th width="15%" class="th_decoradoRowspan">GESTION</th>
                                        <th width="10%" class="th_decoradoRowspan">ESTADO GESTION</th>
                                        <th width="10%" class="th_decoradoRowspan">FECHA HORA INICIO</th>
                                        <th width="10%" class="th_decoradoRowspan">FECHA HORA FIN</th>
                                        <th width="7%" class="th_decoradoRowspan">ESTADO</th>
                                        <th width="5%" class="th_decoradoRowspan">COSTO</th>
                                        <th width="8%" class="th_decoradoRowspan">ACCION</th>
                                    </tr>
                                </thead>
                                <tbody>
                            <%
                                int i = 1;
                                String aux = "";
                                for(VentaMatricula vm : vms){
                                    if(vm.getGestion().getEstado() == 1)
                                        aux = "VIGENTE";
                                    else
                                        aux = "EN ESPERA";
                            %>          
                                    <tr class="tr_decorado">
                                        <td class="th_decorado"><%=vm.getGestion().getFacultad().getDepartamento().getNombre()%></td>
                                        <td class="th_decorado"><%=vm.getGestion().getFacultad().getNombre()%></td>
                                        <td class="th_decorado"><%=vm.getGestion().getNombre()%></td>
                                        <td class="th_decorado"><%=aux%></td>
                                        <td class="th_decorado"><%=vm.getFechaIni()%></td>
                                        <td class="th_decorado"><%=vm.getFechaFin()%></td>
                                        <td class="th_decorado"><%=(vm.isActivo())?"ACTIVO":"CANCELADO"%></td>
                                        <td class="th_decorado"><%=UtilTransaccion.redondear(vm.getCosto(), 2)%></td>
                                        <td class="td_decoradoDerecha" style="text-align: center">
                                      <% if(vm.isActivo()){%>      
                                            <input type="button" value="Cancelar" onclick="$.fn.cancelarVentaMatricula(<%=vm.getIdVentaMatricula()%>)" class="botonRep" title="Pulsa aqui para cancelar la venta de matrÃ­cula"/>
                                        <%}else System.out.println("&nbsp;");
                                        %>
                                        </td>
                                    </tr>
                            <%
                                    i++;
                                }
                                if(i == 1){
                                    out.write("<tr class='tr_decorado'>");
                                    out.write("     <td class='td_decorado' colspan='9' style='text-align:center'><span style='color:red'>No existen venta de matrÃ­culas habilitadas!</span></td>");
                                    out.write("</tr>");
                                }
                            %>
                                </tbody>
                            </table>
                            <br/>
                            </div> <!-- End id="listGestiones" -->
                                
                            <div id="dialogo"><br/>
                                <h2 class="decorado" id="titleForm"></h2><br/>
                                <form id="formVentaMatricula">
                                    <input type="hidden" name="accion" id="accion" value="0" />
                                    <input type="hidden" name="idVentaMatricula" id="idGestion" value="0" />
                                    <div style="clear:both;">
                                        <label class="form_align35" >Gesti&oacute;n: </label>
                                        <select name="idGestion" id="idGestion" class="required form_input_align" title="Seleccione Unidad Acad&eacute;mica">
                                        <%
                                            out.println("<option value=''>Seleccione</option>");
                                            for(Gestion g:gestiones)
                                                out.println("<option value='"+g.getIdGestion()+"'>"+g.getFacultad().getNombre()+", "+g.getNombre()+"</option>");
                                        %>
                                        </select>
                                        <label class="error">*</label>
                                    </div>
                                    <div style="clear: both;">
                                        <label class="form_align35">Fecha Inicio:</label>
                                        <input type="text" name="fechaIni" id="fechaIni" class="form_input_align_NoFloat required" size="10" readonly="true"/>
                                        <label for="horaIni">Hrs. </label>
                                        <input type="text" name="horaIni" id="horaIni.[1]" class="form_input_align_NoFloat required" size="6" readonly="true"/>
                                        <label class="error">*</label>
                                    </div>
                                    <div style="clear: both;">
                                        <label class="form_align35">Fecha Fin:</label>
                                        <input type="text" name="fechaFin" id="fechaFin" class="form_input_align_NoFloat required" size="10" readonly="true"/>
                                        <label for="horaFin">Hrs. </label>
                                        <input type="text" name="horaFin" id="horaFin.[1]" class="form_input_align_NoFloat required" size="6" readonly="true"/>
                                        <label class="error">*</label>
                                    </div>
                                    <div style="clear:both;">
                                        <label class="form_align35" >Costo Matr&iacute;cula: </label>
                                        <input type="text" name="costo" id="costo" value="" class="required number form_input_align" title="Ingrese el costo de matr&iacute;cula" maxlength="5" size="6"/>&nbsp;Bs.
                                        <label class="error">*</label>
                                    </div>
                                </form>
                            </div> <!-- FIN DIV id="dialogo" -->
                            </center>
                        </div>
                    </div><!--end of leftPan-->
                </div><!--end of content-wrapper-->
            </div><!--end of body-wrap-->
            
            <!-- footer -->
            
        </div>
    </body>
</html>